package com.demo.java.OD1_50.OD7;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

/**
 * @author bug菌
 * @Source 公众号：猿圈奇妙屋
 * @des： 考勤信息问题
 * @url： https://blog.csdn.net/weixin_43970743/article/details/145502751
 */
public class OdMain {

    /**
     * 判断学生的出勤情况
     *
     * @param str 学生的出勤记录
     * @return 是否符合要求的出勤标准
     */
    public static boolean fullAttendance(String str) {
        Stack<String> myStack = new Stack<>();
        Queue<String> myQueue = new LinkedList<>();
        String[] strs = str.split(" ");
        int absent = 0;
        int myCount = 0;

        for (int i = 0; i < strs.length; i++) {
            String cur = strs[i];

            // 检查是否有超过一次缺席
            if (cur.equals("absent")) {
                if (++absent > 1) return false;
            }

            // 用栈判断是否有连续的迟到或早退
            if (cur.equals("leaveearly") || cur.equals("late")) {
                if (!myStack.isEmpty() && (myStack.peek().equals("late") || myStack.peek().equals("leaveearly"))) {
                    return false;
                } else {
                    myCount++;
                }
            }

            // 入栈和入队
            myStack.push(cur);
            myQueue.offer(cur);

            // 队列判断是否连续7天有超过3次迟到或早退
            if (myQueue.size() == 7 && myCount > 3) {
                return false;
            } else {
                String poll = myQueue.poll();
                if (poll.equals("late") || poll.equals("leaveearly")) {
                    myCount--;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        try (Scanner s = new Scanner(System.in)) {
            String line = s.nextLine();
            System.out.print(fullAttendance(line));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
